package com.ahstu.learning.notepad;

import android.app.Activity;
import android.content.ContentValues;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.ahstu.learning.R;

public class NewActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //requestWindowFeature(featureId)
        setContentView(R.layout.insetnote);
        final EditText edittitle = (EditText) findViewById(R.id.noteedittitle1);
        final EditText editcontext = (EditText) findViewById(R.id.noteedit2);
        final Button finish = (Button) findViewById(R.id.btn_note_protect);
        Button cancel = (Button) findViewById(R.id.btn_note_cancel);
        finish.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                String title = edittitle.getText().toString();
                if (title.equals("")) {
                    Toast.makeText(NewActivity.this, "请输入标题", Toast.LENGTH_SHORT).show();

                    return;

                }
                String content = editcontext.getText().toString();
                Database help = new Database(NewActivity.this, "node.db", null, 1);
                SQLiteDatabase db = help.getWritableDatabase();
                ContentValues value = new ContentValues();
                value.put("title", title);
                value.put("content", content);
                db.insert("thing", null, value);
                Intent intent = new Intent(NewActivity.this, ListActivity.class);
                intent.putExtra("title", title);
                ListActivity.list.finish();
                finish();
                db.close();
                startActivity(intent);


            }

        });

        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }


}
